let app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
    properties: {
      scrollTop: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatscroll()
        }
      },
      item:Object,
      list: {
        type: Array,
        observer: function(newVal, oldVal) {
          this.updatelist()
        }
      },
      bgColor: {
        type: String,
        default: "#fff"
    },
    fontColor: {
        type: String,
        default: "rgba(53, 53, 53, 1.0)"
    },
    descColor: {
        type: String,
        default: "rgba(175, 177, 175, 1.0)"
    },
    styleType: {
        type: String,
        default: "style1"
    }
      },
      data:{
        type: "article"
      },
    lifetimes: {
      ready: function() {
        let that = this;
        const query = wx.createSelectorQuery().in(this)
        setTimeout(() => { 
           query.select('#'+this.data.item.id).boundingClientRect(res=>{
                that.setData({
                  top:res.top
                })
              }).exec();
         }, 0);
       },
        attached: function () {
          var css=stylecss.css(this.data.item.id);
          var anima=stylecss.animated(this.data.item.id);
          this.setData({
            oldanima:anima,
            anima:anima,
            css:css
          })
       }
      },
    methods: {
      updatscroll:function(){
        var nowtop=this.data.scrollTop-this.data.top
        var oldanima=this.data.oldanima
        if(nowtop<=0){
         this.setData({
           anima:oldanima
         })
        }else{
          this.setData({
              anima:''
          })
        }
     },
      jumpurl:function(e){
        wx.navigateTo({ 
          url: '/yb_shopv2/native/all/index?type=article&id='+this.data.list[e.currentTarget.dataset.index].id,
       })
      },
      updatelist:function(){
        this.setData({
          end:true,
          end_show:true
       })
      }
    }
});
